package com.gm.wholesale.module.main.presenter;

import com.gm.commonlib.views.popupwindow.Popupwindow;
import com.gm.wholesale.bluetooth.bean.WeightBean;
import com.gm.wholesale.module.good.bean.GoodBean;
import com.gm.wholesale.module.main.ui.MainActivity;
import com.gm.wholesale.module.order.ui.MainOrderFragment;
import com.gm.wholesale.module.order.view.CreateOrderView;
import com.gm.wholesale.module.order.view.CreateOrderViewByVoice;
import com.gm.wholesale.module.order.view.UpdateOrderViewByVoice;

import java.util.List;

public class CreateOrderUiPre {
    private CreateOrderView createOrderView;
    private CreateOrderViewByVoice createOrderViewByVoice;

    private UpdateOrderViewByVoice updateGoodForVoice;
    private MainOrderFragment mMainOrderFragment;
    private MainActivity mActivity;
    public CreateOrderUiPre(MainActivity activity,MainOrderFragment mainOrderFragment) {
        mMainOrderFragment=mainOrderFragment;
        this.mActivity=activity;
    }

    public void setNumBer(WeightBean weightBean){
        if (createOrderView!=null){
            createOrderView.setBlueNumber(weightBean);
        }
        if (createOrderViewByVoice!=null){
            createOrderViewByVoice.setBlueNumber(weightBean);
        }
        if (updateGoodForVoice!=null){
            updateGoodForVoice.setBlueNumber(weightBean);
        }

    }
    public void showCreateOrderView(GoodBean goodBean) {
        createOrderView = new CreateOrderView(mActivity);
        createOrderView.setICreateOrderListener(goodBean1 -> {
            if (mMainOrderFragment != null) {
                mMainOrderFragment.addGoodBean(goodBean1);
            }
        });
        createOrderView.showChoiceGoodView(mActivity,goodBean);
        Popupwindow.showPopCenterView(mActivity, createOrderView);


    }
    public void createOrder(GoodBean goodBean){
        if (mMainOrderFragment != null) {
            mMainOrderFragment.addGoodBean(goodBean);
        }
    }

    public void showCreateOrderViewByVoice(String goodName) {
       // if (createOrderViewByVoice == null) {
            createOrderViewByVoice = new CreateOrderViewByVoice(mActivity);
       // }
        createOrderViewByVoice.setICreateOrderListener(goodBean1 -> {
            if (mMainOrderFragment != null) {
                mMainOrderFragment.addGoodBean(goodBean1);
            }
        });
        createOrderViewByVoice.showViewByVoice(mActivity,goodName);
        Popupwindow.showPopCenterView(mActivity, createOrderViewByVoice);
    }


    public void updateGoodForVoice(GoodBean goodBean) {
       // if (updateGoodForVoice == null) {
            updateGoodForVoice = new UpdateOrderViewByVoice(mActivity);
       // }
        updateGoodForVoice.setICreateOrderListener(goodBean1 -> {
            if (mMainOrderFragment != null) {
                mMainOrderFragment.addGoodBean(goodBean1);
            }
        });
        updateGoodForVoice.updateGoodForVoice(mActivity,goodBean);
        Popupwindow.showPopCenterView(mActivity, updateGoodForVoice);
    }
}
